import cors from "cors";
import express from "express";
import expressWs from "express-ws";
import fileupload from 'express-fileupload'
import serverConfig from "../../config/server.config";
import { ExpressCustom } from "../../typing.express";

const port = serverConfig.app.port;

const ExpressApp = express() as ExpressCustom;

expressWs(ExpressApp)

// 解决跨域
ExpressApp.use(cors());
ExpressApp.use(express.json());
ExpressApp.use(fileupload());
ExpressApp.use(express.urlencoded({ extended: false }));
ExpressApp.use((err, _req, res, _next) => {
  res.status(400).send(err.message)
})

ExpressApp.listen(port, () => {
  console.log(`服务启动完成，请打开浏览器访问 http://localhost:${port}/`)
})

export default ExpressApp
